from django.shortcuts import render

from apps.message.serializers import Message, MessageSerializers
from utils import restful


def message(request):
    if request.is_ajax():
        # user_id = request.session.get('user_id')
        user_id = request.POST.get('user_id')
        messages = Message.objects.filter(to_id=user_id)
        data = MessageSerializers(messages, many=True).data

        return restful.ok(data=data)

    return render(request, 'message/messages.html')
